import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of, Subject } from 'rxjs';
import { catchError, filter, map } from 'rxjs/operators';
import { SERVER_API_URL } from 'app/app.constants';
// import { Equipment, Result, Page, EquipmentType } from './interface/interface';
// import { LaneGroup } from 'app/public';
// import { ToolsService } from 'app/share';
// import { JUNCTIONM_API_URL, EQUIPMENTM_API_URL } from 'app/app.constants';
import { Router } from '@angular/router';
import { LogManagement } from './interface';
import { ConfigService } from 'app/config/config.service';

@Injectable({
    providedIn: 'root'
})
export class LogManagementService {
    private apiUrl_log_online = this.config.apiUrl.log;
    // private apiUrl_log_online = 'http://192.168.0.56:9592/vnqnoperationlog/log/getLogByPage';
    // private handleError: HandleError;

    private _userConfigData: any;
    configDataExsited = false;

    get userConfigData() {
        return this._userConfigData;
    }

    set userConfigData(data) {
        this._userConfigData = data;
    }

    constructor(private http: HttpClient, private router: Router, private config: ConfigService) {}
    /**
     * get lane config info
     * @param params { juncId: string , isTemp: 0temp??1offcial }
     */
    // 获取用户日志列表
    // getUserLog(): Observable<any> {
    //     const adata = {
    //         checkUserName: String,
    //         uat: String,
    //         startTime: String,
    //         endTime: String
    //     };
    //     const url = `${this.apiUrl_equip_online}/userMgt/user/getUserLog`;
    //     return this.http.get<any>(url);
    // }
    getUserLog(param): Observable<any> {
        return this.http.post<any>(this.apiUrl_log_online + '/vnqnoperationlog/log/getLogByPage', param);
        // return this.http.post<any>(this.apiUrl_log_online, param);
    }

    /**
     * equipment bind
     * @param params { Equipment }
     */

    private handleError<T>(operation = 'operation', result?: T) {
        return (error: any): Observable<T> => {
            // TODO: send the error to remote logging infrastructure
            console.error(error); // log to console instead

            // TODO: better job of transforming error for user consumption
            this.log(`${operation} failed: ${error.message}`);

            // Let the app keep running by returning an empty result.
            return of(result as T);
        };
    }
    private log(message: string) {}
}
